package ui.widget;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

public class TransparentTxtBtn extends CommonStyleBtn {
	private int xpos;
	private int ypos;
	private Color txtColor = Color.BLUE;

	public TransparentTxtBtn() {
		xpos = 2;
		ypos = 17;
		setOpaque(false);
	}

	public TransparentTxtBtn(String txt) {
		this();
		setFont(new Font("黑体", Font.BOLD, 18));
		setText(txt);
	}

	public int getXpos() {
		return xpos;
	}

	public int getYpos() {
		return ypos;
	}

	public void setXpos(int xpos) {
		this.xpos = xpos;
		repaint();
	}

	public void setYpos(int ypos) {
		this.ypos = ypos;
		repaint();
	}

	public void setTxtColor(Color txtColor) {
		this.txtColor = txtColor;
		repaint();
	}

	@Override
	protected void paintComponent(Graphics g) {
		Graphics2D g2d = (Graphics2D) g.create();
		int h = getHeight();
		int w = getWidth();
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0));
		g2d.fillRect(0, 0, w, h);
		g2d.setColor(txtColor);
		g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1));
		g2d.drawString(getText(), xpos, ypos);
		g2d.dispose();
	}
}
